package cn.tt.core.shiro;

import org.springframework.stereotype.Component;

/**
 * @Description Shiro的控制类
 * @Date 2017/7/29 11:46
 * @Since v1.7
 * @Autor Nick
 */
@Component
public class ShiroConfig {

//	/**
//	 * 全局的环境变量的设置
//	 * shiro的拦截
//	 *
//	 * @param environment
//	 * @param adminPath
//	 * @return
//	 */
//	@Bean(name = "shiroFilterChainDefinitions")
//	public String shiroFilterChainDefinitions(Environment environment, @Value("${adminPath}") String adminPath) {
//		Global.resolver = new RelaxedPropertyResolver(environment);
//		String string = "/static/** = anon\n";
//		string += "/userfiles/** = anon\n";
//		string += adminPath + "/basic = basic\n";
//		string += adminPath + "/login = authc\n";
//		string += adminPath + "/logout = logout\n";
//		string += adminPath + "/** = user\n";
//		string += "/ReportServer/** = user";
//		return string;
//	}
//
//	@Bean(name = "basicHttpAuthenticationFilter")
//	public BasicHttpAuthenticationFilter casFilter(@Value("${adminPath:/a}") String adminPath) {
//		BasicHttpAuthenticationFilter basicHttpAuthenticationFilter = new BasicHttpAuthenticationFilter();
//		basicHttpAuthenticationFilter.setLoginUrl(adminPath + "/login");
//		return basicHttpAuthenticationFilter;
//	}
//
//	@Bean(name = "shiroFilter")
//	public ShiroFilterFactoryBean shiroFilterFactoryBean(
//			@Value("${adminPath:/a}") String adminPath,
//			BasicHttpAuthenticationFilter basicHttpAuthenticationFilter,
//			FormAuthenticationFilter formAuthenticationFilter,
//			DefaultWebSecurityManager securityManager,
//			@Qualifier("shiroFilterChainDefinitions") String shiroFilterChainDefinitions) {
//		Map<String, Filter> filters = new HashMap();
//		filters.put("basic", basicHttpAuthenticationFilter);
//		filters.put("authc", formAuthenticationFilter);
//		ShiroFilterFactoryBean bean = new ShiroFilterFactoryBean();
//		bean.setFilters(filters);
//		bean.setSecurityManager(securityManager);
//		bean.setLoginUrl(adminPath + "/login");
//		bean.setSuccessUrl(adminPath + "?login");
//		bean.setFilterChainDefinitions(shiroFilterChainDefinitions);
//		return bean;
//	}
//
//	@Bean(name = "shiroCacheManager")
//	public EhCacheManager shiroCacheManager(net.sf.ehcache.CacheManager manager) {
//		EhCacheManager ehCacheManager = new EhCacheManager();
//		ehCacheManager.setCacheManager(manager);
//		return ehCacheManager;
//	}
//
//	@Bean(name = "sessionManager")
//	public SessionManager sessionManager(CacheSessionDAO dao) {
//		SessionManager sessionManager = new SessionManager();
//		sessionManager.setSessionDAO(dao);
//		sessionManager.setGlobalSessionTimeout(86400000);
//		sessionManager.setSessionValidationInterval(1800000);
//		sessionManager.setSessionValidationSchedulerEnabled(true);
//		sessionManager.setSessionIdCookie(new SimpleCookie("wolfking.jeesite.session.id"));
//		sessionManager.setSessionIdCookieEnabled(true);
//		return sessionManager;
//	}
//
//	@Bean(name = "securityManager")
//	public DefaultWebSecurityManager defaultWebSecurityManager(
//			SystemAuthorizingRealm systemAuthorizingRealm,
//			SessionManager sessionManager,
//			EhCacheManager ehCacheManager) {
//		DefaultWebSecurityManager defaultWebSecurityManager = new DefaultWebSecurityManager();
//		defaultWebSecurityManager.setSessionManager(sessionManager);
//		defaultWebSecurityManager.setCacheManager(ehCacheManager);
//		defaultWebSecurityManager.setRealm(systemAuthorizingRealm);
//		return defaultWebSecurityManager;
//	}
//
//	@Bean
//	public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(
//			DefaultWebSecurityManager defaultWebSecurityManager) {
//		AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor = new AuthorizationAttributeSourceAdvisor();
//		authorizationAttributeSourceAdvisor.setSecurityManager(defaultWebSecurityManager);
//		return authorizationAttributeSourceAdvisor;
//	}
//
//	@Bean
//	public FilterRegistrationBean filterRegistrationBean() {
//		FilterRegistrationBean filterRegistration = new FilterRegistrationBean();
//		filterRegistration.setFilter(new DelegatingFilterProxy("shiroFilter"));
//		filterRegistration.addInitParameter("targetFilterLifecycle", "true");
//		filterRegistration.setEnabled(true);
//		filterRegistration.addUrlPatterns("/*");
//		return filterRegistration;
//	}
//
//	@Bean(name = "lifecycleBeanPostProcessor")
//	public LifecycleBeanPostProcessor lifecycleBeanPostProcessor() {
//		return new LifecycleBeanPostProcessor();
//	}
//
//	@Bean
//	@DependsOn("lifecycleBeanPostProcessor")
//	public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() {
//		DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator = new DefaultAdvisorAutoProxyCreator();
//		defaultAdvisorAutoProxyCreator.setProxyTargetClass(true);
//		return defaultAdvisorAutoProxyCreator;
//	}
}